package com.sgcc.fj.pmos.e_fj_order.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.fj.pmos.common.bean.IndentOrContractBean;
import com.sgcc.fj.pmos.common.http.HttpInterConst;
import com.sgcc.fj.pmos.common.utils.DateUtils;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.fj.pmos.common.utils.TextUtil;

/**
 * 订单
 */
public class IndentAdapter extends BaseQuickAdapter<IndentOrContractBean, BaseViewHolder> {

    private Context mContext;

    public IndentAdapter(Context context) {
        super(R.layout.item_indent);
        mContext = context;
    }

    public interface OnItemClickListener {
        /**
         * 公司名
         *
         * @param position
         * @param bean
         */
        void OnCompanyNameClickListener(int position, IndentOrContractBean bean);

        /**
         * 确认
         *
         * @param position
         * @param bean
         */
        void OnConfirmClickListener(int position, IndentOrContractBean bean);

        /**
         * 撤销议价
         *
         * @param position
         * @param bean
         */
        void OnUndoBargainingClickListener(int position, IndentOrContractBean bean);

        /**
         * 驳回议价
         *
         * @param position
         * @param bean
         */
        void OnRejectedBargainingClickListener(int position, IndentOrContractBean bean);

        /**
         * 查看详情
         *
         * @param position
         * @param bean
         */
        void OnLookInfoListener(int position, IndentOrContractBean bean);
    }

    private OnItemClickListener mOnItemClickListener;

    public void setItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, IndentOrContractBean bean) {

        String img_url = HttpInterConst.BASEURL_IMG + bean.getFileIdComb();
        ImageView imageView = baseViewHolder.getView(R.id.iv_package_logo);
        Glide.with(mContext).load(img_url).placeholder(R.mipmap.order_deft).error(R.mipmap.order_deft).into(imageView);

//        baseViewHolder.setText(R.id.tv_combName, bean.getSellingPoint());
        baseViewHolder.setText(R.id.tv_combName, TextUtil.getName(bean.getSellingPoint(),bean.getCreditRating()));
        baseViewHolder.setText(R.id.tv_company_name, bean.getMembersSdName());

        String start_time = TextUtils.isEmpty(bean.getStartDate()) ? "" : DateUtils.getStrng_to_Times_ymd_2(bean.getStartDate());
        String end_time = TextUtils.isEmpty(bean.getEndDate()) ? "" : DateUtils.getStrng_to_Times_ymd_2(bean.getEndDate());
        baseViewHolder.setText(R.id.tv_time, start_time + "~" + end_time);

        String relStatus = TextUtils.isEmpty(bean.getRelStatus()) ? "" : bean.getRelStatus();

        baseViewHolder.setGone(R.id.tv_cxyj, true);
        baseViewHolder.setGone(R.id.tv_bhyj, true);
        baseViewHolder.setGone(R.id.tv_confirm, true);
        switch (relStatus) {
            case "1":
                baseViewHolder.setText(R.id.tv_order_status, "待确认");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#FEB004"));
                if ("203".equals(bean.getModificationType()) && "102".equals(bean.getmStatus())) {//议价 - 待售电公司确认 2个按钮
                    baseViewHolder.setGone(R.id.tv_cxyj, false);
                    baseViewHolder.setGone(R.id.tv_mStatus,false);
                }

                if ("203".equals(bean.getModificationType()) && "104".equals(bean.getmStatus())) {//议价 - 售电公司已确认 3个按钮
                    baseViewHolder.setGone(R.id.tv_bhyj, false);
                    baseViewHolder.setGone(R.id.tv_confirm, false);
                    baseViewHolder.setGone(R.id.tv_mStatus,false);
                }

//                if ("203".equals(bean.getModificationType()) && "105".equals(bean.getmStatus())) {//议价 - 待售电公司确认 2个按钮
//                    baseViewHolder.setText(R.id.tv_order_status, "已关闭");
//                    baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#666666"));
//                    baseViewHolder.setGone(R.id.tv_mStatus,true);
//                }
//                if ("203".equals(bean.getModificationType()) && "106".equals(bean.getmStatus())) {//议价 - 待售电公司确认 2个按钮
//                    baseViewHolder.setText(R.id.tv_order_status, "已关闭");
//                    baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#666666"));
//                    baseViewHolder.setGone(R.id.tv_mStatus,true);
//                }
//                if ("203".equals(bean.getModificationType()) && "107".equals(bean.getmStatus())) {//议价 - 待售电公司确认 2个按钮
//                    baseViewHolder.setText(R.id.tv_order_status, "已关闭");
//                    baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#666666"));
//                    baseViewHolder.setGone(R.id.tv_mStatus,true);
//                }

                break;
            case "3":
                baseViewHolder.setText(R.id.tv_order_status, "已生效");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#2BC98E"));
                baseViewHolder.setGone(R.id.tv_mStatus,false);
                break;
            case "4":
                baseViewHolder.setText(R.id.tv_order_status, "已关闭");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#666666"));
                baseViewHolder.setGone(R.id.tv_mStatus,true);
//                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#666666"));
                break;
            case "5":
                baseViewHolder.setText(R.id.tv_order_status, "已解约");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#FF2E2E"));
                baseViewHolder.setGone(R.id.tv_mStatus,false);
                break;
            case "6":
                baseViewHolder.setText(R.id.tv_order_status, "已完结");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#999999"));
                baseViewHolder.setGone(R.id.tv_mStatus,false);
                break;
            case "9":
                baseViewHolder.setGone(R.id.tv_mStatus,false);
                baseViewHolder.setText(R.id.tv_order_status, "待评价");
                baseViewHolder.setTextColor(R.id.tv_order_status, Color.parseColor("#0092FF"));
                break;
        }

        String result = status_left(bean.getModificationType()) + status_right(bean.getmStatus());
        baseViewHolder.setText(R.id.tv_mStatus, result);

        baseViewHolder.getView(R.id.rl_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnLookInfoListener(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_cxyj).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnUndoBargainingClickListener(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnConfirmClickListener(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_company_name).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnCompanyNameClickListener(getItemPosition(bean), bean);
                }
            }
        });
        baseViewHolder.getView(R.id.tv_bhyj).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mOnItemClickListener != null) {
                    mOnItemClickListener.OnRejectedBargainingClickListener(getItemPosition(bean), bean);
                }
            }
        });
    }

    public String status_left(String modificationType) {
        String result = "";
        switch (modificationType) {
            case "201":
                result = "合约建立";
                break;
            case "202":
                result = "电量变更";
                break;
            case "203":
                result = "议价";
                break;
            case "204":
                result = "合约解除";
                break;
            case "205":
                result = "电价变更";
                break;
        }
        return result;
    }

    public String status_right(String mStatus) {
        String result = "";
        switch (mStatus) {
            case "101":
                result = "待用户确认";
                break;
            case "102":
                result = "待售电公司确认";
                break;
            case "103":
                result = "用户已确认";
                break;
            case "104":
                result = "售电公司已确认";
                break;
            case "105":
                result = "用户已驳回";
                break;
            case "106":
                result = "售电公司已驳回";
                break;
            case "107":
                result = "用户已撤回";
                break;
            case "108":
                result = "售电公司已撤回";
                break;
        }
        return result;
    }

}
